<?php

require_once 'XML/RPC2/Client.php';
if(!defined('APP_ROOT_PATH')) 
define('APP_ROOT_PATH',str_replace('edm.php','',str_replace('\\','/',__FILE__)));
if(!function_exists('app_conf'))
{
$sys_config = require APP_ROOT_PATH.'system/config.php';
function app_conf($name)
{
return stripslashes($GLOBALS['sys_config'][$name]);
}
}
$options = array(
'prefix'=>'1.5.',
'encoding'=>'utf-8',
'debug'=>false			
);
$api_url='http://api.lian-wo.com/';# api地址，不需要更改
$username= app_conf('EDM_USERNAME');# 您的账号
$password= app_conf('EDM_PASSWORD');# 您的密码
$client = XML_RPC2_Client::create($api_url,$options);
$token = $client->login($username,$password);
function create_email($email,$client,$token)
{
try 
{
$group_id = $client->createGroup($token,'easethink_'.time());
$group=array($group_id);
$email_id=$client->createEmail($token,$email,$group);
return $group_id;
}catch (XML_RPC2_FaultException $e) {
return 'Exception #'.$e->getFaultCode() .' : '.$e->getFaultString();
}catch (Exception $e) {
return 'Exception : '.$e->getMessage();
}
}
function create_template($subject,$send_email,$send_name,$content,$client,$token)
{
try {
$array['subject']=$subject;
$array['send_email']=$send_email;
$array['send_name']=$send_name;
$array['reply_email']=$send_email;
$array['reply_name']=$send_name;
$array['content']=$content;
$template_id=$client->createTemplate($token,'easethink_'.time(),$array);
return $template_id;
}catch (XML_RPC2_FaultException $e) {
return 'Exception #'.$e->getFaultCode() .' : '.$e->getFaultString();
}catch (Exception $e) {
return 'Exception : '.$e->getMessage();
}
}
function send_mail($email,$subject,$send_email,$send_name,$content,$send_time,$client,$token)
{
$send_group = intval(create_email($email,$client,$token));
$template_id = intval(create_template($subject,$send_email,$send_name,$content,$client,$token));
$send_group = $send_group.'';
try {
$forbidden_group='-1';
$client->createPlan($token,$template_id,$send_time,$send_group,$forbidden_group);
return 'success';
}catch (XML_RPC2_FaultException $e) {
return 'Exception #'.$e->getFaultCode() .' : '.$e->getFaultString();
}catch (Exception $e) {
return 'Exception : '.$e->getMessage();
}
}

?>